<template>
	<view>
		<u-sticky>
			<u-tabs-swiper ref="uTabs" active-color="#20cbd4" :list="list" :current="current" @change="tabsChange" :is-scroll="false"></u-tabs-swiper>
		</u-sticky>
		<swiper class="swiper" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
			<swiper-item class="swiper-item">
				<scroll-view class="swiper" scroll-y>
					<empty v-if="isEmpty&&isShow" :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
					<view class="warp" @click="jumpPage(item)" v-if="!isEmpty&&isShow" v-for="(item, index) in couponList">
						<view class="left">
							<view class="faceValue">
								<view>¥</view>
								<view class="price">{{item.reduce_price}}</view>
								<view>优惠券</view>
							</view>
							<view class="info">满{{item.min_price}}可用</view>
							<view class="info">有效期：{{item.start_time}}至{{item.end_time}}</view>
						</view>
						<view class="right">
							<u-button :custom-style="customStyle" @click="jumpPage(item)" hover-class="none" shape="circle" size="mini">立即使用</u-button>
						</view>
					</view>
					<u-loadmore :status="status" color="#909399" v-if="!isEmpty&&isShow"/>
				</scroll-view>
			</swiper-item>
			<swiper-item class="swiper-item">
				<scroll-view class="swiper" scroll-y>
					<empty v-if="isEmpty&&isShow" :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
					<view class="warp" v-if="!isEmpty&&isShow" v-for="(item, index) in couponList">
						<view class="left">
							<view class="faceValue">
								<view>¥</view>
								<view class="price">{{item.reduce_price}}</view>
								<view>优惠券</view>
							</view>
							<view class="info">满{{item.min_price}}可用</view>
							<view class="info">有效期：{{item.start_time}}至{{item.end_time}}</view>
						</view>
						<view class="right">
							<u-button :disabled="true" :custom-style="customStyle1"  hover-class="none" shape="circle" size="mini">已使用</u-button>
						</view>
					</view>
					<u-loadmore :status="status" color="#909399" v-if="!isEmpty&&isShow"/>
				</scroll-view>
			</swiper-item>
			<swiper-item class="swiper-item">
				<scroll-view class="swiper" scroll-y>
					<empty v-if="isEmpty&&isShow" :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
					<view class="warp" v-if="!isEmpty&&isShow" v-for="(item, index) in couponList">
						<view class="left">
							<view class="faceValue">
								<view>¥</view>
								<view class="price">{{item.reduce_price}}</view>
								<view>优惠券</view>
							</view>
							<view class="info">满{{item.min_price}}可用</view>
							<view class="info">有效期：{{item.start_time}}至{{item.end_time}}</view>
						</view>
						<view class="right">
							<u-button :disabled="true" :custom-style="customStyle1"  hover-class="none" shape="circle" size="mini">已过期</u-button>
						</view>
					</view>
					<u-loadmore :status="status" color="#909399" v-if="!isEmpty&&isShow"/>
				</scroll-view>
			</swiper-item>
		</swiper>
		<login-model ref="loginModel"></login-model>
		<hoverMenu></hoverMenu>
	</view>
</template>

<script>
	import hoverMenu from "@/components/public/sa-hover-menu.vue";
	import loginModel from "@/components/public/loginModel.vue";
	import empty from "@/components/public/empty.vue";
	import {listCoupon} from "@/common/api.js";
	export default {
		components: {
			empty,
			loginModel,
			hoverMenu
		},
		data() {
			return {
				list: [{
					name: '可使用'
				}, {
					name: '已使用'
				}, {
					name: '已过期'
				}],
				current: 0, 
				swiperCurrent: 0, 
				customStyle:{
					background:'#13797f',
					color:'#20cbd4'
				},
				customStyle1:{
					background:'#c8c9cc',
					color:'#909399'
				},
				couponList: [],
				status: 'loadmore',
				pageSize: 10,
				pageStart: 1,
				total:0,
				isShow:false,
				isEmpty:false,
				emptyImg:"https://yunxingzhan.oss-cn-hangzhou.aliyuncs.com/miniprogram/images/images/empty_goods.png",
				emptyTxt:"暂无优惠券",
				type:'',
				ids:""
			};
		},
		onLoad: function(options) {
			let type = options.type || '';
			let ids = options.ids || '';
			this.type = type;
			this.ids = ids;
			this.isShow = false;
			this.couponList=[];
			this.pageStart = 1;
			this.selectCouponList();
		},
		onReachBottom: function() {
			if(this.total/(this.pageStart*this.pageSize)>1){
				this.pageStart++;
				this.selectCouponList();
			}else{
				this.status = 'nomore';
			}
		},
		methods: {
			floatTouchClick(index){
				this.$uniApi.floatTouch(index);
			},
			selectCouponList(){
				listCoupon(this,{page:this.pageStart,limit:this.pageSize,type:this.swiperCurrent+1,ids:this.ids});
			},
			tabsChange(index) {
				this.isShow = false;
				this.swiperCurrent = index;
			},
			transition(e) {
				this.isShow = false;
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				//每次切换时重新查询数据
				this.status = 'loadmore';
				this.isEmpty = false;
				this.couponList=[];
				this.pageStart = 1;
				this.selectCouponList();
			},
			jumpPage(item){
				if(this.type=='select'){
					uni.setStorageSync('user_coupon_id', item.user_coupon_id);
					uni.setStorageSync('reduce_price', item.reduce_price);
					uni.navigateBack(-1)
				}else{
					uni.setStorageSync('coupon_type', "0");
					uni.switchTab({
						url:"/pages/tabBar/classify"
					})
				}
			}
		}
	};
</script>

<style>
	page{
		font-family: PingFang SC;
		background: #f6f6f6;
	}
	.swiper{
		width: 100%;
		height: calc(100vh - var(--window-top));
		padding-bottom: 80rpx;
	}
	.warp{
		width: 700rpx;
		height: 175rpx;
		background-size:contain;
		background-image: url(https://yunxingzhan.oss-cn-hangzhou.aliyuncs.com/miniprogram/images/images/coupon_bg1.png);
		background-repeat:no-repeat no-repeat;
		display: flex;
		justify-content: space-between;
		padding: 20rpx 0;
		margin: 30rpx;
	}
	.left{
		width: 440rpx;
		margin-left: 80rpx;
	}
	.faceValue{
		display: flex;
		color: #0e595d;
		align-items: flex-end;
		font-size: 25rpx;
	}
	.price{
		font-size: 50rpx;
		line-height: 50rpx;
		font-weight: 700;
		margin-right: 10rpx;
	}
	.info{
		font-size: 20rpx;
		margin-top: 10rpx;
		color: #13797f;
	}
	.right{
		width: 140rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>